package com.fingard.dsp.bank.directbank.pab02.Util.api.utils;

/**
 * 类功能: 16进制数据工具类
 * 
 */
public class DataTools {

	/**
	 * 获得2进制长度头
	 * 
	 * @param len
	 *            位数
	 * @param num
	 * @return
	 */
	public static byte[] getLength(int len, int num) {
		byte[] lengthBuf = new byte[len];

		for (int i = 0; i < len; i++) {
			lengthBuf[i] = (byte) ((num >>> ((len - i - 1) * 8)) & 0xFF);
		}

		return lengthBuf;
	}

	/**
	 * 获得数据长度
	 * 
	 * @param length
	 * @return
	 */
	public static int getLenth(int begin, byte[] head) {

		int retLen = 0;
		int length = head.length;

		for (int i = begin; i < length; i++) {
			retLen = retLen + ((head[i] & 0xFF) << ((length - i - 1) * 8));
		}
		return retLen;
	}

}
